<?php
Class Application_Model_DbTable_Contact extends Zend_Db_Table_Abstract
{
	protected $_name = 'contact';
	
	public function findContacts($list)
	{
		$list = (int)($list);
		return $this->fetchAll('list_id = ' . $list)->toArray();
	}
	
	public function getContact($id)
	{
		$id = (int)($id);
		$row = $this->fetchRow('id = ' . $id);
		if (!$row)
		{
			throw new Exception("could not found row");
		}
		return $row->toArray();
	}
	
	public function addContact($email, $confirmed, $state, $list_id)
	{
		$data = array(
				'email' => $email,
				'confirmed' => $confirmed,
				'state' => $state,
				'list_id' => $list_id,
				);
		$this->insert($data);
	}
	
	public function updateContact($id, $email, $confirmed, $state, $list_id)
	{
		$data = array(
				'email' => $email,
				'confirmed' => $confirmed,
				'state' => $state,
				'list_id' => $list_id,
				);
		$this->update($data, 'id =' . (int)$id);
	}
	
	public function deleteContact($id)
	{
		$this->delete('id =' . (int)$id);
	}
}